package com.sise.parkinglot.controller;

import com.sise.parkinglot.bean.CodeMsg;
import com.sise.parkinglot.entity.SitInfo;
import com.sise.parkinglot.service.ISitInfoService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author ZJ
 */
@RestController
@RequestMapping("/parkinglot/sit-info")
public class SitInfoController {

    @Resource
    private ISitInfoService sitInfoService;

    @PostMapping("/querySitList")
    public CodeMsg<List<SitInfo>> querySitList(@RequestBody Map<String, Object> map) {
        return sitInfoService.querySitList(map);
    }

    @PostMapping("/addSit")
    public CodeMsg<String> addSit(@RequestBody SitInfo sitInfo) {
        return sitInfoService.addSit(sitInfo);
    }

    @PostMapping("/notAvailableSit")
    public CodeMsg<String> notAvailableSit(@RequestBody int[] stationIds) {
        return sitInfoService.updateState(stationIds, 3);
    }

    @PostMapping("/removeSit")
    public CodeMsg<String> removeSit(@RequestBody int[] stationIds) {
        return sitInfoService.removeSit(stationIds);
    }

    @PostMapping("/availableSit")
    public CodeMsg<String> availableSit(@RequestBody int[] stationIds) {
        return sitInfoService.updateState(stationIds, 1);
    }

    @PostMapping("/updateSit")
    public CodeMsg<String> updateSit(@RequestBody SitInfo sitInfo) {
        return sitInfoService.updateSit(sitInfo);
    }

    @PostMapping("/usedSit")
    public CodeMsg<String> usedSit(@RequestBody int[] stationIds) {
        return sitInfoService.updateState(stationIds, 2);
    }

}
